<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>卖点合集</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>

    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/Jquery.easyui.tooltip.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border: none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:20px;">
                    <label class="item-label">品类：</label>
                    <select id="categorySelect" name="categoryCode" class="easyui-combobox" style="width:100px;">
                    </select>
                    <label class="item-label">品牌：</label>
                    <select id="brandSelect" name="brandCode" class="easyui-combobox" style="width:100px;">
                    </select>

                    <label class="item-label">卖点：</label>
                    <!--<input type="text" name="code"  class="easyui-textbox" style="width:100px;"/>-->
                    <input type="text" class="easyui-textbox" name="sellMerit1" style="width:100px">
                    <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                </div>

            </form>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" data-options="fitColumns:true,scrollBarSize:0">
                <thead>
                <tr>
                    <th data-options="field:'id',checkbox:true,align:'center'"></th>
                    <th data-options="field:'categoryName',align:'center'" width="80">品类</th>
                    <th data-options="field:'brandName',align:'center'" width="100">品牌</th>
                    <th data-options="field:'modelCode',align:'center'" width="100">型号码</th>
                    <th data-options="field:'modelName',align:'center'" width="100">型号名</th>
                    <th data-options="field:'sellMerit',align:'center'" width="180">卖点</th>
                    <th data-options="field:'operateUsername',align:'center'" width="100">申请人</th>
                    <th data-options="field:'createTime',align:'center'" width="140">操作时间</th>

                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    function initPage() {
        initUserCategorySelect("categorySelect",function (code) {
            categoryCode = $("#categorySelect").combobox("getValue");
            initBrandSelectC("brandSelect",function () {initSeries(categoryCode,"brandSelect")},null,code);
        });
        searchBy(1,100);
    }
    $(function(){
        var height = $(window).height();
        var nav_height = $("#nav")._outerHeight();
        var ff_height = $("#ff").height();
        var table_height = height-nav_height-ff_height-40;
        $("#datagrid").css("max-height",table_height);
        $("#datagrid").datagrid({
            rownumbers:true,
            pagination:true,
            idField:"id",
            checkOnSelect:false,
            toolbar:[{
                text:'确定',
                handler:function(){
                    updateDate();
                }
            }],onLoadSuccess:function(data){
                $("#datagrid").datagrid("clearChecked");

                var tableTd = $('div.datagrid-body td[field="wrongModelName"]'); //productname是列名
                tableTd.each(function () {
                    var $this = $(this);
                    var index = $this.parent('tr').attr('datagrid-row-index');
                    var rows =  $('#datagrid').datagrid('getRows');
                    var currentRow = rows[index];
                    var content = '<div style=" max-width:700px;word-break: break-all; word-wrap: break-word;">' + currentRow.wrongModelName + '</div>'; //productname是列名
                    $this.tips({ content: content, wrapColor: 'black' });
                });
            },
        }).datagrid("getPager").pagination({
            onSelectPage:searchBy
        });
        aRecords("卖点合集","/webapp/pages/product/modifyRecord/sellMeritlist")
        initPage();
    });

    function searchBy(page,size) {
        var dtd = $.Deferred();
        var data = getFormData(document.getElementById("ff"));
        var pager = {page:page,size:size};
        if(!size){
            pager['page']= 1;
            pager['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||100;
        }
        var jsonobj = {};
        jsonobj = $.extend(true,jsonobj,transfer(data));
        jsonobj = JSON.stringify(jsonobj);
        // console.log(jsonobj)
        $.ajax({
            url:config.url + "/modifyRecord/sellMeritPage?"+transfer2url(pager),
            type:'post',
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            complete:function () {
                $.messager.progress("close");
            },
            success:function (data) {
                $.messager.progress("close");
                if(data){
                    globalData = data;
                    $("#datagrid").datagrid("loadData",data);
                    dtd.resolve();
                }
            },
            error:function (XMLHttpRequest,textStatus,errorThrown) {

            }
        });
        return dtd.promise();
    }
    function styler(text){
        if(text){
            return '<span style="font-size: 14px;font-weight: bold;color: #ff9f26;">' + text + '</span>';
        }else{
            return;
        }
    }
    function dj(text){
        if(text=="I"){
            return '型号重复';
        }else if(text==" II"){
            return "品牌错误";
        }else if(text==" III"){
            return "品类错误";
        }else if(text==" IV"){
            return "禁用";
        }else {
            return "其他";
        }
    }
    function styleg(text){
        if(text){
            return '<span style="font-size: 14px;font-weight: bold;color: #4fc8d6;">' + text + '</span>';
        }else{
            return;
        }

    }
</script>
<!--
<script type="text/javascript" src="/webapp/js/common/pagelist.js"></script>
-->
<script type="text/javascript">
    function actions(val, row){
        if(row.updateStatus=="UNDONE"){

            return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
                "style='width:60px;' onclick='edit(\""+row.id+"\",\""+row.categoryCode+"\")'>修改</a>&nbsp;&nbsp;"+
                "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;' onclick='updateStatus(\""+row.id+"\", \"" + row.entityStatus + "\")'>"+"启用"+"</a>";
        }
    }
    function edit(id,categoryCode){
        window.parent.addTab("修改型号码", "/webapp/pages/product/modifyRecord/add.html?id="+id+"&categoryCode="+categoryCode);
    }
    function updateStatus(id,entityStatus){
        $.messager.confirm("提示","您确定启用型号吗？",function (f) {
            if(f){
                $.ajax({
                    url:config.url+"/modifyRecord/"+id,
                    type:"DELETE",
                    dataType:"json",
                    data:JSON.stringify(id),
                    contentType:"application/json;charset=UTF-8",
                    xhrFields:{withCredentials:true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"操作进行中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    success:function (data) {
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    error:function (data) {

                    }
                });
            }
        });
    }
    function updateDate() {
        var selectedRow = $("#datagrid").datagrid("getChecked");
        if (selectedRow != null && selectedRow.length > 0) {
            var codes = selectedRow.map(function (item) {
                return item.id;
            });
            var ids = "";
            for (var id of codes) {
                ids += id + ",";
            }
            $.messager.confirm("提示", "您确定要修改历史数据吗?</br>结果不可逆呦！！！", function (r) {
                if (r) {
                    $.ajax({
                        url: config.url + "/modifyRecord/updateDate",
                        type: 'POST',
                        xhrFields: {withCredentials: true},
                        dataType: 'json',
                        data: {ids: ids},
                        complete:function(){
                            $.messager.progress("close");
                        },
                        success:function(data){
                            if(data.code==200){
                                $.messager.alert("提示",data.msg,"info",function () {
                                    searchBy(1,100);
                                });
                            }else {
                                $.messager.alert("提示",data.msg,"error");
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, thrown) {
                        }
                    });
                }
            });
        } else {
            $.messager.alert("提示", "请选择相关记录", "error");
            return false;
        }
    }
    $("#ff").keydown(function (event) {
        var e = event || window.event;
        var keyCode = e.keyCode || e.which;
        if(keyCode=="13"){
            searchBy();
        }
    });
    function hoveringShow(value) {
        return "<span title='" + value + "'>" + value + "</span>";
    }
</script>
</html>
